<template>
	<view class="body">
		<view class="set-userinfo">
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">头像</view>
				<view class="set-userinfo-list-right" @click="changeimage">
					<view class="set-userinfo-list-right-pic">
						<image :src="userpic" mode="aspectFill" lazy-load></image>
					</view>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">昵称</view>
				<view class="set-userinfo-list-right">
					<input class="set-userinfo-list-right-name" type="text" v-model="username" />
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">性别</view>
				<view class="set-userinfo-list-right" @click="changeOne('sex')">
					<view class="set-userinfo-list-right-name">
						{{sex}}
					</view>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">生日</view>
				<view class="set-userinfo-list-right">
					<picker mode="date" :value="birthday" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="set-userinfo-list-right-name">{{birthday}}</view>
					</picker>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">情感</view>
				<view class="set-userinfo-list-right" @click="changeOne('qg')">
					<view class="set-userinfo-list-right-name">
						{{qg}}
					</view>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">职业</view>
				<view class="set-userinfo-list-right" @click="changeOne('job')">
					<view class="set-userinfo-list-right-name">
						{{job}}
					</view>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<view class="set-userinfo-list">
				<view class="set-userinfo-list-left">家乡</view>
				<view class="set-userinfo-list-right" @click="openPicker">
					<view class="set-userinfo-list-right-name">
						{{pickerText}}
					</view>
					<view class="set-userinfo-list-right-icon icon iconfont">&#xe668;</view>
				</view>

			</view>
			<button class="button" type="default" @click="submit">完成</button>
		</view>
		<mpvue-city-picker theme-color="#007aff" ref="mpvueCityPicker" :picker-value-default="pickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker>



	</view>
</template>

<script>
	let sex = ['不限', '男', '女']
	let qg = ['已婚', '未婚']
	let job = ['秘密', 'IT', '老师', '业务员']
	import mpvueCityPicker from "./mpvue-citypicker/mpvueCityPicker.vue"
	export default {
		components:{
			mpvueCityPicker
		},
		data() {
			return {
				userpic:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fbf6fe5f0-4e5c-4dd1-9545-f58151164f0c%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1688030544&t=0eb95982f55004824ffbd3cd0aedd1f9",
				username: "自来也",
				sex: "不限",
				qg: "未婚",
				job: "IT",
				birthday: "1989-11-5",
				pickerValueDefault:[0,2,1],
				pickerText:"北京市-市辖区-西城区",


			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			onConfirm(e){			
				this.pickerText=JSON.stringify(e.label)
				console.log(this.pickerText);
			},
			openPicker(){
				this.$refs.mpvueCityPicker.show()
			},
			changeimage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //压缩图
					success: (res) => {
						console.log(JSON.stringify(res.tempFilePaths));
						this.userpic = res.tempFilePaths
					}
				});

			},
			bindDateChange: function(e) {
				this.birthday = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// 单列选择
			changeOne(val) {
				let arr = [1, 2, 3];
				console.log(val);
				switch (val) {
					case 'sex':
						arr = sex;
						break;
					case 'qg':
						arr = qg;
						break;
					case 'job':
						arr = job;
						break;
				}
				uni.showActionSheet({
					itemList: arr,
					success: (res) => {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						switch (val) {
							case 'sex':
								this.sex = arr[res.tapIndex]
								break;
							case 'qg':
								this.qg = arr[res.tapIndex]
								break;
							case 'job':
								this.job = arr[res.tapIndex]
								break;
						}
					},

				});
			},
			submit() {

			}

		}
	}
</script>

<style lang="scss" scoped>
	@import url("iconfont.css");
	.body {
		margin: 20rpx 25rpx;

		.set-userinfo {
			border-top: 1rpx solid #F2F2F2;

			.set-userinfo-list {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 25rpx;
				border-bottom: 1rpx solid #F2F2F2;

				.set-userinfo-list-left {
					font-size: 30rpx;
					color: #989898;
					font-weight: 500;
				}

				.set-userinfo-list-right {
					display: flex;
					justify-content: center;
					align-items: center;

					.set-userinfo-list-right-pic {
						width: 90rpx;
						height: 90rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 100%;
						}
					}

					.set-userinfo-list-right-name {
						display: flex;
						align-items: center;
						font-size: 30rpx;

						text-align: right;
					}

					.set-userinfo-list-right-icon {
						font-size: 45rpx;
						color: #989898;
						margin-left: 30rpx;
					}
				}
			}

			.button {
				margin-top: 30rpx;
				width: 95%;
				background-color: #007aff;
				font-size: 30rpx;
				color: #ffffff;
				border: 0;
			}
		}

	}
</style>